TRSA component

Methods	Events

TRSA is an implementation of the RSA public key encryption algorithm. It can generate keys, encode and decode data.

Using the Component

1. Generate a key-pair with the GenerateKey method or load an existing key using the methods of the TRSAKey class.

2. Load the data you wish to encode/decode into a buffer.

3. Call the Encode method to encode or Decode method to decode the contents of the buffer.

Encode( KEY, MSG ) encodes MSG with the given KEY. Decode( KEY, MSG ) decodes MSG with the given KEY.

If PUB,PRIV is a key-pair and MSG is a message, the following equations are true:

   Decode( PRIV, Encode( PUB, MSG )) = MSG

   Decode( PUB, Encode( PRIV, MSG )) = MSG

Example for using the RSA public-key encryption algorithm

Let A and B be two persons. Both of them has two keys: a public and a private one. Everybody knows the public keys, but private keys are only known by their owners. Suppose that A wants to send a message to B. A encodes the message with B’s public key. After that, the message can be decoded only by B with his private key.

See Also

About the shareware version, TRSAKey class


Methods

Decode

Encode

GenerateKey


Events

OnProgress


Decode method

Applies to

TRSA component

Declaration

procedure Decode(key: TRSAKey; input:Pointer; il:Longint; var output:Pointer; var ol:Longint);

Description

Decodes a data vector with the specified key. The input parameter should point to the beginning of the data vector to decode, il is the length of data vector in bytes. The method allocates a vector where the output data placed and returns its address in output and its length (in bytes) in ol. You should free the output vector after use with the FreeMem method.

See Also

TRSAKey class, Encode


Encode method

Applies to

TRSA component

Declaration

procedure Encode(key: TRSAKey;input:Pointer;il:Longint;var output:Pointer; var ol:Longint);

Description

Encodes a data vector with the specified key. The input parameter should point to the beginning of data vector to encode, il is the length of data vector in bytes. The method allocates a vector where the output data placed and returns its address in output and its length (in bytes) in ol. You should free the output vector after use with the FreeMem method.

See Also

TRSAKey class, Decode


GenerateKey method

Applies to

TRSA component

Declaration

procedure GenerateKey(i:Word;var pub,priv: TRSAKey);

Description

Generates a key-pair (a public and a private key). Parameter i is the length of the key in 16-bit units. (i=10 means that the key length is 160 bits). Possible values for i are between 1 and 200. Longer keys cause slower processing (key generation, encoding, decoding can take several minutes) but higher safety. Suggested value for i is between 30 and 50. The pub and priv key object should be created before you call this method, the results will be placed into these objects.

See Also

TRSAKey class


OnProgress event

Applies to

TRSA component

Declaration

property OnProgress: TNotifyEvent;

Description

This event called during any calculation algorithms (coding, key generating).

During key generation, the algorithm finds two large prime numbers and it cannot be determined exactly how many numbers should be tested so it calls OnProgress for each number tested.

During encoding and decoding, the algorithm divides the data vector into packages according to the key length. OnProgress is called 'key length' times.


TRSAKey class

Description

The TRSAKey class manages an RSA key (public or private). TRSAKey has the following public members:

m_mod, m_a: TInteger;	The key consists of these large integer numbers.

procedure Save(f: String);	Saves the key to the given file.

procedure Load(f: String); 	Loads the key from the given file.

TInteger is a non-documented class which represents large integer numbers. Use TInteger.ToStr (returns a string) to convert the number to its string representation.


Shareware version

The shareware version of TRSA has the following limitations:

•	The component can be used only in the Delphi development environment.

•	The maximum allowed key length is 10.